import request from '@/axios'
import {
  ResourceType,
  UpdateResourceOrg,
  UpdateResourceOrgType,
  UpdateResourceRoleType,
  UpdateResourceUser,
  UpdateResourceUserType
} from './types'

//分页获取资源
export const pageApi = (data) => {
  return request.post({ url: '/rbac-server/rbac/resource/page', data })
}

//新增资源
export const addApi = (data) => {
  return request.post({ url: '/rbac-server/rbac/resource/add', data })
}
//获取资源
export const getApi = (params) => {
  return request.get({ url: '/rbac-server/rbac/resource/get', params })
}
//删除资源
export const delApi = (params) => {
  return request.delete({ url: '/rbac-server/rbac/resource/delete', params })
}
//修改资源
export const updateApi = (data) => {
  return request.put({ url: '/rbac-server/rbac/resource/update', data })
}

//获取启动的非公共资源
export const listResourceApi = (): Promise<IResponse<ResourceType[]>> => {
  return request.get({ url: '/rbac-server/rbac/resource/list' })
}
//保存配置
export const authorizeApi = (data, loading) => {
  return request.post({ url: '/rbac-server/rbac/resource/authorize', data }, loading)
}

//获取配置树
export const authorizeTreeApi = (params) => {
  return request.get({ url: '/rbac-server/rbac/resource/authorizeTree', params })
}
//获取配置数据
export const loadAuthorizeApi = (resId: string) => {
  return request.get({ url: '/rbac-server/rbac/resource/loadAuthorize', params: { resId } })
}

//获取组织关联的资源
export const getResourceOrgApi = (orgId: string) => {
  return request.get({ url: '/rbac-server/rbac/resource/getResourceOrg', params: { orgId } })
}

//获取用户关联的资源
export const getResourceUserApi = (userId: string) => {
  return request.get({ url: '/rbac-server/rbac/resource/getResourceUser', params: { userId } })
}

//获取组织类型关联的资源
export const getResourceOrgTypeApi = (orgTypeId: string) => {
  return request.get({
    url: '/rbac-server/rbac/resource/getResourceOrgType',
    params: { orgTypeId }
  })
}

//获取用户类型关联的资源
export const getResourceUserTypeApi = (userTypeId: string) => {
  return request.get({
    url: '/rbac-server/rbac/resource/getResourceUserType',
    params: { userTypeId }
  })
}

//获取角色类型关联的资源
export const getResourceRoleTypeApi = (roleTypeId: string) => {
  return request.get({
    url: '/rbac-server/rbac/resource/getResourceRoleType',
    params: { roleTypeId }
  })
}

//修改组织关联的资源
export const updateResourceOrgApi = (data: UpdateResourceOrg) => {
  return request.put({ url: '/rbac-server/rbac/resource/updateResourceOrg', data })
}

//修改用户关联的资源
export const updateResourceUserApi = (data: UpdateResourceUser) => {
  return request.put({ url: '/rbac-server/rbac/resource/updateResourceUser', data })
}

//修改组织类型关联的资源
export const updateResourceOrgTypeApi = (data: UpdateResourceOrgType) => {
  return request.put({ url: '/rbac-server/rbac/resource/updateResourceOrgType', data })
}

//修改用户类型关联的资源
export const updateResourceUserTypeApi = (data: UpdateResourceUserType) => {
  return request.put({ url: '/rbac-server/rbac/resource/updateResourceUserType', data })
}

//修改角色类型关联的资源
export const updateResourceRoleTypeApi = (data: UpdateResourceRoleType) => {
  return request.put({ url: '/rbac-server/rbac/resource/updateResourceRoleType', data })
}

//分页查询组织和资源关联
export const orgPageApi = (data) => {
  return request.post({ url: '/rbac-server/rbac/resource/resourceOrgPage', data })
}

//分页查询用户和资源关联
export const userPageApi = (data) => {
  return request.post({ url: '/rbac-server/rbac/resource/resourceUserPage', data })
}

//分页查询组织类型和资源关联
export const orgTypePageApi = (data) => {
  return request.post({ url: '/rbac-server/rbac/resource/resourceOrgTypePage', data })
}

//分页查询用户类型和资源关联
export const userTypePageApi = (data) => {
  return request.post({ url: '/rbac-server/rbac/resource/resourceUserTypePage', data })
}

//分页查询角色类型和资源关联
export const roleTypePageApi = (data) => {
  return request.post({ url: '/rbac-server/rbac/resource/resourceRoleTypePage', data })
}

//移除组织关联的资源
export const removeOrgApi = (params) => {
  return request.delete({ url: '/rbac-server/rbac/resource/removeResourceOrg', params })
}

//移除用户和资源关联
export const removeUserApi = (params) => {
  return request.delete({ url: '/rbac-server/rbac/resource/removeResourceUser', params })
}

//移除组织类型和资源关联
export const removeOrgTypeApi = (params) => {
  return request.delete({ url: '/rbac-server/rbac/resource/removeResourceOrgType', params })
}

//移除用户类型和资源关联
export const removeUserTypeApi = (params) => {
  return request.delete({ url: '/rbac-server/rbac/resource/removeResourceUserType', params })
}

//移除角色类型和资源关联
export const removeRoleTypeApi = (params) => {
  return request.delete({ url: '/rbac-server/rbac/resource/removeResourceRoleType', params })
}
